home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_duke / mapprt.zip / MAP.C < prev    next >
C/C++ Source or Header  |  1996-06-18  |  18KB  |  705 lines

  1. /*
  2.  
  3.    MAP.C
  4.  
  5.    Oliver Kraus
  6.    kraus@lrs.e-technik.uni-erlangen.de
  7.  
  8. */
  9.  
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13. #include "map.h"
  14. #include "names.h"
  15.  
  16. #define MAP_NONE              0
  17. #define MAP_ASSAULT_TROOPER   1
  18. #define MAP_ASSAULT_CAPTAIN   2
  19. #define MAP_PIC_COP           3
  20. #define MAP_RECON_PATROL      4
  21. #define MAP_OCTABRAIN         5
  22. #define MAP_ENFORCER          6
  23. #define MAP_SENTRY_DRONE      7
  24. #define MAP_ASSAULT_COMMANDER 8
  25. #define MAP_PROTOZOID_SLIMER  9
  26. #define MAP_BATTLELORD       10
  27. #define MAP_OVERLORD         11
  28. #define MAP_CYCLOID_EMPEROR  12
  29. #define MAP_TURRET           13
  30. #define MAP_EGG              14
  31. #define MAP_ROTATE_GUN       15        /* same as MAP_TURRET? */
  32.  
  33. #define MAP_BLUE_CARD       100
  34. #define MAP_RED_CARD        101
  35. #define MAP_YELLOW_CARD     102
  36.  
  37. #define MAP_EXIT            200
  38. #define MAP_BONUS_EXIT      201
  39.  
  40. struct _map_sprite_to_item
  41. {
  42.    short picnum;
  43.    short palette;
  44.    short item;
  45. };
  46. typedef struct _map_sprite_to_item map_sprite_to_item;
  47.  
  48. struct _map_item_info_struct
  49. {
  50.    short typ;
  51.    short item;
  52.    long cnt;
  53.    char *id;
  54.    char *name;
  55.    char *altname;
  56. };
  57. typedef struct _map_item_info_struct map_item_info_struct;
  58.  
  59. map_item_info_struct map_item_info[] =
  60. {
  61.    { 0              , MAP_NONE              , 0L, "??", "unknown"              , NULL          },
  62.    { MAP_TYP_MONSTER, MAP_ASSAULT_CAPTAIN   , 0L, "AC", "Assault Captain"      , "Lizman"      },
  63.    { MAP_TYP_MONSTER, MAP_ASSAULT_COMMANDER , 0L, "AM", "Assault Commander"    , NULL          },
  64.    { MAP_TYP_MONSTER, MAP_ASSAULT_TROOPER   , 0L, "AT", "Assault Trooper"      , "Liztroop"    },
  65.    { MAP_TYP_MONSTER, MAP_BATTLELORD        , 0L, "BL", "Battlelord"           , "Boss 1"      },
  66.    { MAP_TYP_MONSTER, MAP_CYCLOID_EMPEROR   , 0L, "CE", "Cycloid Emperor"      , "Boss 3"      },
  67.    { MAP_TYP_MONSTER, MAP_EGG               , 0L, "EG", "Egg"                  , NULL          },
  68.    { MAP_TYP_MONSTER, MAP_ENFORCER          , 0L, "EN", "Enforcer"             , "Mini Boss 1" },
  69.    { MAP_TYP_MONSTER, MAP_OCTABRAIN         , 0L, "OB", "Octabrain"            , NULL          },
  70.    { MAP_TYP_MONSTER, MAP_OVERLORD          , 0L, "OL", "Overlord"             , "Boss 2"      },
  71.    { MAP_TYP_MONSTER, MAP_PIC_COP           , 0L, "PC", "Pic Cop"              , NULL          },
  72.    { MAP_TYP_MONSTER, MAP_PROTOZOID_SLIMER  , 0L, "PS", "Protozoid Slimer"     , NULL          },
  73.    { MAP_TYP_MONSTER, MAP_ROTATE_GUN        , 0L, "RG", "Rotate Gun"           , NULL          },
  74.    { MAP_TYP_MONSTER, MAP_RECON_PATROL      , 0L, "RP", "Recon Patrol Car"     , NULL          },
  75.    { MAP_TYP_MONSTER, MAP_SENTRY_DRONE      , 0L, "SD", "Sentry Drone"         , NULL          },
  76.    { MAP_TYP_MONSTER, MAP_TURRET            , 0L, "TU", "Turret"               , NULL          },
  77.  
  78.    { MAP_TYP_CARD,    MAP_BLUE_CARD         , 0L, "BC", "Blue Card"            , NULL          },
  79.    { MAP_TYP_CARD,    MAP_RED_CARD          , 0L, "RC", "Red Card"             , NULL          },
  80.    { MAP_TYP_CARD,    MAP_YELLOW_CARD       , 0L, "YC", "Yellow Card"          , NULL          },
  81.  
  82.    { -1             , MAP_NONE              , 0L, NULL, NULL                  }
  83. };
  84.  
  85. char *map_get_item_id(int idx)
  86. {
  87.    if ( idx < 0 )
  88.       return "";
  89.    return map_item_info[idx].id;
  90. }
  91.  
  92.  
  93. char *map_get_item_string(int idx)
  94. {
  95.    if ( idx < 0 )
  96.       return "";
  97.    return map_item_info[idx].name;
  98. }
  99.  
  100. int map_get_item_typ(int idx)
  101. {
  102.    if ( idx < 0 )
  103.       return 0;
  104.    return (int)map_item_info[idx].typ;
  105. }
  106.  
  107. int map_get_item_cnt(int idx)
  108. {
  109.    if ( idx < 0 )
  110.       return 0;
  111.    return (int)map_item_info[idx].cnt;
  112. }
  113.  
  114.  
  115. map_sprite_to_item map_to_item[] =
  116. {
  117.    { LIZTROOP          , -1,  MAP_ASSAULT_TROOPER    },
  118.    { LIZTROOPRUNNING   , -1,  MAP_ASSAULT_TROOPER    },
  119.    { LIZTROOPSTAYPUT   , -1,  MAP_ASSAULT_TROOPER    },
  120.    { LIZTOP            , -1,  MAP_ASSAULT_TROOPER    },
  121.    { LIZTROOPSHOOT     , -1,  MAP_ASSAULT_TROOPER    },
  122.    { LIZTROOPJETPACK   , -1,  MAP_ASSAULT_TROOPER    },
  123.    { LIZTROOPDSPRITE   , -1,  MAP_ASSAULT_TROOPER    },
  124.    { LIZTROOPONTOILET  , -1,  MAP_ASSAULT_TROOPER    },
  125.    { LIZTROOPDUCKING   , -1,  MAP_ASSAULT_TROOPER    },
  126.  
  127.    { OCTABRAIN         , -1,  MAP_OCTABRAIN          },
  128.    { OCTABRAINSTAYPUT  , -1,  MAP_OCTABRAIN          },
  129.    { OCTATOP           , -1,  MAP_OCTABRAIN          },
  130.  
  131.    { DRONE             , -1,  MAP_SENTRY_DRONE       },
  132.  
  133.    { COMMANDER         , -1,  MAP_ASSAULT_COMMANDER  },
  134.    { COMMANDERSTAYPUT  , -1,  MAP_ASSAULT_COMMANDER  },
  135.  
  136.    { RECON             , -1,  MAP_RECON_PATROL       },
  137.  
  138.    { PIGCOP            , -1,  MAP_PIC_COP            },
  139.    { PIGCOPSTAYPUT     , -1,  MAP_PIC_COP            },
  140.    { PIGCOPDIVE        , -1,  MAP_PIC_COP            },
  141.    { PIGTOP            , -1,  MAP_PIC_COP            },
  142.  
  143.    { LIZMAN            , -1,  MAP_ASSAULT_CAPTAIN    },
  144.    { LIZMANSTAYPUT     , -1,  MAP_ASSAULT_CAPTAIN    },
  145.    { LIZMANSPITTING    , -1,  MAP_ASSAULT_CAPTAIN    },
  146.    { LIZMANFEEDING     , -1,  MAP_ASSAULT_CAPTAIN    },
  147.    { LIZMANJUMP        , -1,  MAP_ASSAULT_CAPTAIN    },
  148.  
  149.    { BOSS1             , -1,  MAP_BATTLELORD         },
  150.    { BOSS1STAYPUT      , -1,  MAP_BATTLELORD         },
  151.    { BOSS1SHOOT        , -1,  MAP_BATTLELORD         },
  152.    { BOSS1LOB          , -1,  MAP_BATTLELORD         },
  153.    { BOSSTOP           , -1,  MAP_BATTLELORD         },
  154.  
  155.    { BOSS3             , -1,  MAP_OVERLORD           },   /* strange BOSS2/BOSS3 */
  156.  
  157.    { BOSS2             , -1,  MAP_CYCLOID_EMPEROR    },
  158.  
  159.    { EGG               , -1,  MAP_EGG                },
  160.  
  161.    { ROTATEGUN         , -1,  MAP_ROTATE_GUN         },
  162.  
  163.    { ACCESSCARD        ,  0,  MAP_BLUE_CARD          },
  164.    { ACCESSCARD        , 21,  MAP_RED_CARD           },
  165.    { ACCESSCARD        , 23,  MAP_YELLOW_CARD        },
  166.  
  167.    { -1, -1, -1}
  168. };
  169.  
  170. int map_get_info_idx(short picnum, short palette)
  171. {
  172.    int i, j;
  173.    i = 0;
  174.    while ( map_to_item[i].item >= 0 )
  175.    {
  176.       if ( map_to_item[i].picnum == picnum )
  177.       {
  178.          if ( map_to_item[i].palette < 0 )
  179.             break;
  180.          if ( map_to_item[i].palette == palette )
  181.             break;
  182.       }
  183.       i++;
  184.    }
  185.    if ( map_to_item[i].item < 0 )
  186.       return -1;
  187.    j = 0;
  188.    while ( map_item_info[j].typ >= 0  )
  189.    {
  190.       if ( map_item_info[j].item == map_to_item[i].item )
  191.          break;
  192.       j++;
  193.    }
  194.    if ( map_item_info[j].typ < 0  )
  195.       return -1;
  196.    return j;
  197. }
  198.  
  199. int is_map_file(char *name)
  200. {
  201.    long lval, pos;
  202.    short sval;
  203.    map_player_struct pl;
  204.    FILE *fp;
  205.  
  206.    pos = 0L;
  207.    fp = fopen(name, "rb");
  208.    if ( fp == NULL )
  209.       return 0;
  210.  
  211.    if ( fread(&lval, sizeof(long), 1, fp) != 1 )
  212.    {
  213.       fclose(fp);
  214.       return 0;
  215.    }
  216.    pos += sizeof(long);
  217.  
  218.    /* check version number */
  219.    if ( lval < 7 )
  220.    {
  221.       fclose(fp);
  222.       return 0;
  223.    }
  224.    if ( lval > 100 )
  225.    {
  226.       fclose(fp);
  227.       return 0;
  228.    }
  229.  
  230.  
  231.    if ( fread(&pl, sizeof(map_player_struct), 1, fp) != 1 )
  232.    {
  233.       fclose(fp);
  234.       return 0;
  235.    }
  236.    if ( pl.ang >= 2048 )
  237.    {
  238.       fclose(fp);
  239.       return 0;
  240.    }
  241.    pos += sizeof(map_player_struct);
  242.  
  243.    if ( fread(&sval, sizeof(short), 1, fp) != 1 )
  244.    {
  245.       fclose(fp);
  246.       return 0;
  247.    }
  248.    if ( sval < 0 )
  249.    {
  250.       fclose(fp);
  251.       return 0;
  252.    }
  253.    pos += (long)sizeof(short);
  254.    pos += (long)sizeof(map_sector_struct)*(long)sval;
  255.    if ( fseek(fp, pos, SEEK_SET) != 0 )
  256.    {
  257.       fclose(fp);
  258.       return 0;
  259.    }
  260.    if ( ftell(fp) != pos )
  261.    {
  262.       fclose(fp);
  263.       return 0;
  264.    }
  265.  
  266.    if ( fread(&sval, sizeof(short), 1, fp) != 1 )
  267.    {
  268.       fclose(fp);
  269.       return 0;
  270.    }
  271.    if ( sval < 0 )
  272.    {
  273.       fclose(fp);
  274.       return 0;
  275.    }
  276.    pos += (long)sizeof(short);
  277.    pos += (long)sizeof(map_wall_struct)*(long)sval;
  278.    if ( fseek(fp, pos, SEEK_SET) != 0 )
  279.    {
  280.       fclose(fp);
  281.       return 0;
  282.    }
  283.    if ( ftell(fp) != pos )
  284.    {
  285.       fclose(fp);
  286.       return 0;
  287.    }
  288.  
  289.    if ( fread(&sval, sizeof(short), 1, fp) != 1 )
  290.    {
  291.       fclose(fp);
  292.       return 0;
  293.    }
  294.    if ( sval < 0 )
  295.    {
  296.       fclose(fp);
  297.       return 0;
  298.    }
  299.    pos += (long)sizeof(short);
  300.    pos += (long)sizeof(map_sprite_struct)*(long)sval;
  301.    if ( fseek(fp, pos, SEEK_SET) != 0 )
  302.    {
  303.       fclose(fp);
  304.       return 0;
  305.    }
  306.    if ( ftell(fp) != pos )
  307.    {
  308.       fclose(fp);
  309.       return 0;
  310.    }
  311.  
  312.    if ( fgetc(fp) != EOF )
  313.    {
  314.       fclose(fp);
  315.       return 0;
  316.    }
  317.  
  318.    fclose(fp);
  319.    return 1;
  320. }
  321.  
  322. void map_name_cut(char *s)
  323. {
  324.    size_t i = 0;
  325.    while( s[i] != '\0' )
  326.    {
  327.       if ( s[i] == '.' )
  328.       {
  329.          s[i] = '\0';
  330.          break;
  331.       }
  332.       i++;
  333.    }
  334.  
  335. }
  336.  
  337. int map_name_split(char *dest, long *val, char *src)
  338. {
  339.    size_t len, i;
  340.    len = strlen(src);
  341.    i = len;
  342.    while( i > 0 )
  343.    {
  344.       i--;
  345.       if ( !isdigit(src[i]) )
  346.       {
  347.          i++;
  348.          break;
  349.       }
  350.    }
  351.    strncpy(dest, src, i);
  352.    dest[i] = '\0';
  353.    if ( i == len )
  354.       return 0;
  355.    *val = atol(src+i);
  356.    return 1;
  357. }
  358.  
  359. int map_name_compare(char *n1, char *n2)
  360. {
  361.    int ret, r1, r2;
  362.    long v1, v2;
  363.    static char s1[14];
  364.    static char s2[14];
  365.    static char t1[14];
  366.    static char t2[14];
  367.  
  368.    strncpy(t1, n1, 12);
  369.    strncpy(t2, n2, 12);
  370.    t1[12] = '\0';
  371.    t2[12] = '\0';
  372.    map_name_cut(t1);
  373.    map_name_cut(t2);
  374.  
  375.    r1 = map_name_split(s1, &v1, t1);
  376.    r2 = map_name_split(s2, &v2, t2);
  377.  
  378.    if ( r1 != 0 && r2 != 0 )
  379.    {
  380.       ret = strcmp(s1, s2);
  381.       if ( ret == 0 )
  382.       {
  383.          if ( v1 < v2 )
  384.             ret = -1;
  385.          else if ( v1 > v2 )
  386.             ret = 1;
  387.       }
  388.    }
  389.    else
  390.    {
  391.       ret = strcmp(t1, t2);
  392.    }
  393.    return ret;
  394. }
  395.  
  396. /*
  397.    if 'fp' is NULL, a filepointer is generated with
  398.    fopen and fname
  399. */
  400. map_type map_Open(char *fname, FILE *fp)
  401. {
  402.    map_type map;
  403.    int is_close_fp = 0;
  404.  
  405.    if ( fname == NULL )
  406.       return NULL;
  407.  
  408.    if ( fp == NULL )
  409.    {
  410.       fp = fopen(fname, "rb");
  411.       if ( fp == NULL )
  412.          return NULL;
  413.       is_close_fp = 1;
  414.    }
  415.  
  416.    map = (map_type)malloc(sizeof(map_struct));
  417.    if ( map != NULL )
  418.    {
  419.       map->fname = (char *)malloc(strlen(fname)+1);
  420.       if ( map->fname != NULL )
  421.       {
  422.          strcpy(map->fname, fname);
  423.          map->is_close_fp = is_close_fp;
  424.          map->fp = fp;
  425.          map->sec_list = NULL;
  426.          map->wall_list = NULL;
  427.          map->sprite_list = NULL;
  428.          map_SetMonster(map);
  429.          map_SetCard(map);
  430.          return map;
  431.       }
  432.       free(map);
  433.    }
  434.  
  435.    if ( is_close_fp != 0 )
  436.       fclose(fp);
  437.    return NULL;
  438. }
  439.  
  440. void map_Close(map_type map)
  441. {
  442.    if ( map != NULL )
  443.    {
  444.       if ( map->sec_list != NULL )
  445.          free(map->sec_list);
  446.       if ( map->wall_list != NULL )
  447.          free(map->wall_list);
  448.       if ( map->sprite_list != NULL )
  449.          free(map->sprite_list);
  450.       if ( map->is_close_fp != 0 )
  451.          fclose(map->fp);
  452.       free(map->fname);
  453.       free(map);
  454.    }
  455. }
  456.  
  457. short map_GetShort(map_type map)
  458. {
  459.    short x;
  460.    if ( fread(&x, sizeof(short), 1, map->fp) != 1 )
  461.    {
  462.       perror("read 16 Bit");
  463.       return -1;
  464.    }
  465.    return x;
  466. }
  467.  
  468. int map_read_version(map_type map)
  469. {
  470.    char *task = "read version";
  471.    if ( fread(&(map->version), sizeof(long), 1, map->fp) != 1 )
  472.    {
  473.       perror(task);
  474.       return 0;
  475.    }
  476.    return 1;
  477. }
  478.  
  479.  
  480. int map_read_player_pos(map_type map)
  481. {
  482.    char *task = "read player pos";
  483.    if ( fread(&(map->player), sizeof(map_player_struct), 1, map->fp) != 1 )
  484.    {
  485.       perror(task);
  486.       return 0;
  487.    }
  488.    return 1;
  489. }
  490.  
  491. int map_read_sector_list(map_type map)
  492. {
  493.    char *task = "read sector list";
  494.    map->sec_cnt = map_GetShort(map);
  495.    if ( map->sec_cnt < 0 )
  496.       return 0;
  497.    if ( map->sec_list != NULL )
  498.       free(map->sec_list);
  499.    map->sec_list = (map_sector_struct *)
  500.       malloc(sizeof(map_sector_struct)*(size_t)map->sec_cnt);
  501.    if ( map->sec_list == NULL )
  502.    {
  503.       fprintf( map->fp, "%s: out of memory\n", task);
  504.       return 0;
  505.    }
  506.    if ( fread((void *)(map->sec_list),
  507.         sizeof(map_sector_struct),
  508.         (size_t)map->sec_cnt, map->fp) != map->sec_cnt )
  509.    {
  510.       perror(task);
  511.       return 0;
  512.    }
  513.    return 1;
  514. }
  515.  
  516. int map_read_wall_list(map_type map)
  517. {
  518.    char *task = "read wall list";
  519.    map->wall_cnt = map_GetShort(map);
  520.    if ( map->wall_cnt < 0 )
  521.       return 0;
  522.    if ( map->wall_list != NULL )
  523.       free(map->wall_list);
  524.    map->wall_list = (map_wall_struct *)
  525.       malloc(sizeof(map_wall_struct)*(size_t)map->wall_cnt);
  526.    if ( map->wall_list == NULL )
  527.    {
  528.       fprintf( map->fp, "%s: out of memory\n", task);
  529.       return 0;
  530.    }
  531.    if ( fread((void *)(map->wall_list),
  532.         sizeof(map_wall_struct),
  533.         (size_t)map->wall_cnt, map->fp) != map->wall_cnt )
  534.    {
  535.       perror(task);
  536.       return 0;
  537.    }
  538.    return 1;
  539. }
  540.  
  541. int map_read_sprite_list(map_type map)
  542. {
  543.    char *task = "read sprite list";
  544.    map->sprite_cnt = map_GetShort(map);
  545.    if ( map->sprite_cnt < 0 )
  546.       return 0;
  547.    if ( map->sprite_list != NULL )
  548.       free(map->sprite_list);
  549.    map->sprite_list = (map_sprite_struct *)
  550.       malloc(sizeof(map_sprite_struct)*(size_t)map->sprite_cnt);
  551.    if ( map->sprite_list == NULL )
  552.    {
  553.       fprintf( map->fp, "%s: out of memory\n", task);
  554.       return 0;
  555.    }
  556.    if ( fread((void *)(map->sprite_list),
  557.         sizeof(map_sprite_struct),
  558.         (size_t)map->sprite_cnt, map->fp) != map->sprite_cnt )
  559.    {
  560.       perror(task);
  561.       return 0;
  562.    }
  563.    return 1;
  564. }
  565.  
  566. int map_Read(map_type map, long pos)
  567. {
  568.    if ( fseek(map->fp, pos, SEEK_SET) != 0 )
  569.    {
  570.       perror("file seek");
  571.       return 0;
  572.    }
  573.    if ( map_read_version(map) == 0 )
  574.       return 0;
  575.    if ( map_read_player_pos(map) == 0 )
  576.       return 0;
  577.    if ( map_read_sector_list(map) == 0 )
  578.       return 0;
  579.    if ( map_read_wall_list(map) == 0 )
  580.       return 0;
  581.    if ( map_read_sprite_list(map) == 0 )
  582.       return 0;
  583.    return 1;
  584. }
  585.  
  586. /* calculate the size of the map, ignoring texture 0 walls */
  587. int map_CalculateSize(map_type map)
  588. {
  589.    short i, j;
  590.    short wallnum, wallidx;
  591.    long x, y;
  592.  
  593.    map->min_x = 0x07fffffffL;
  594.    map->min_y = 0x07fffffffL;
  595.    map->max_x = -0x07fffffffL;
  596.    map->max_y = -0x07fffffffL;
  597.  
  598.    for( i = 0; i < map->sec_cnt; i++ )
  599.    {
  600.       wallnum = map->sec_list[i].wallnum;
  601.       wallidx = map->sec_list[i].wallptr;
  602.       if (
  603.             map->sec_list[i].ceilingstat != 0 ||
  604.             map->sec_list[i].floorstat != 0 ||
  605.             map->sec_list[i].ceilingshade != 0 ||
  606.             map->sec_list[i].ceilingpal != 0 ||
  607.             map->sec_list[i].ceilingxpanning != 0 ||
  608.             map->sec_list[i].ceilingypanning != 0 ||
  609.             map->sec_list[i].floorshade != 0 ||
  610.             map->sec_list[i].floorpal != 0 ||
  611.             map->sec_list[i].floorxpanning != 0 ||
  612.             map->sec_list[i].floorypanning != 0 ||
  613.             map->sec_list[i].visibility != 0 ||
  614.             map->sec_list[i].filler != 0 ||
  615.             map->sec_list[i].lotag != 0 ||
  616.             map->sec_list[i].hitag != 0
  617.           )
  618.       {
  619.          for( j = 0; j < wallnum; j++ )
  620.          {
  621.             x = map->wall_list[wallidx].x;
  622.             y = map->wall_list[wallidx].y;
  623.  
  624.             /* NOTE: To ignore logos on the map, art with idx 0 is ignored */
  625.             /* hopeing, that nobody assigns textures to his logo */
  626.             /* well... wrong see e3l2.map of duke3d: checking more stuff */
  627.             if ( map->wall_list[wallidx].picnum != 0 )
  628.             {
  629.                if ( map->min_x > x )
  630.                   map->min_x = x;
  631.                if ( map->min_y > y )
  632.                   map->min_y = y;
  633.                if ( map->max_x < x )
  634.                   map->max_x = x;
  635.                if ( map->max_y < y )
  636.                   map->max_y = y;
  637.             }
  638.             wallidx = map->wall_list[wallidx].point2;
  639.          }
  640.       }
  641.    }
  642.  
  643.    /*
  644.    for( i = 0; i < map->wall_cnt; i++ )
  645.    {
  646.       if ( map->min_x > map->wall_list[i].x )
  647.          map->min_x = map->wall_list[i].x;
  648.       if ( map->min_y > map->wall_list[i].y )
  649.          map->min_y = map->wall_list[i].y;
  650.       if ( map->max_x < map->wall_list[i].x )
  651.          map->max_x = map->wall_list[i].x;
  652.       if ( map->max_y < map->wall_list[i].y )
  653.          map->max_y = map->wall_list[i].y;
  654.    }
  655.    */
  656.    return 1;
  657. }
  658.  
  659. int map_cnt_sprites(map_type map)
  660. {
  661.    int j;
  662.    int idx;
  663.    map_sprite_struct *sprite;
  664.    short i;
  665.  
  666.    j = 0;
  667.    while ( map_item_info[j].typ >= 0  )
  668.    {
  669.       map_item_info[j].cnt = 0L;
  670.       j++;
  671.    }
  672.  
  673.    for( i = 0; i < map->sprite_cnt; i++ )
  674.    {
  675.       sprite = map->sprite_list+i;
  676.       idx = map_get_info_idx(sprite->picnum, sprite->pal);
  677.       if ( idx >= 0 )
  678.       {
  679.               
  680.  
  681.          if ( map_get_item_typ(idx) == MAP_TYP_MONSTER &&
  682.               map->is_monster == 0 )
  683.             continue;
  684.  
  685.          if ( map_get_item_typ(idx) == MAP_TYP_CARD &&
  686.               map->is_card == 0 )
  687.             continue;
  688.  
  689.          map_item_info[idx].cnt++;
  690.       }
  691.    }
  692.  
  693.    map->legend_item_cnt = 0;
  694.  
  695.    j = 0;
  696.    while ( map_item_info[j].typ >= 0  )
  697.    {
  698.       if ( map_item_info[j].cnt != 0L )
  699.          map->legend_item_cnt++;
  700.       j++;
  701.    }
  702.  
  703.    return map->legend_item_cnt;
  704. }
  705.